package com.hdhere.core.configuration;

import com.hdhere.core.http.session.MyHttpSessionIdResolver;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.DefaultCookieSerializer;
import org.springframework.session.web.http.HttpSessionIdResolver;

/**
 * Created by dus on 2018/12/2.
 */
@ConditionalOnWebApplication
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800)
public class HttpSessionConfig {

    @Bean
    public HttpSessionIdResolver httpSessionIdResolver() {
        MyHttpSessionIdResolver httpSessionIdResolver = new MyHttpSessionIdResolver();
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        cookieSerializer.setUseBase64Encoding(false);
        httpSessionIdResolver.setCookieSerializer(cookieSerializer);
        return httpSessionIdResolver;
    }

//
//    @Bean
//    RedisSerializer<Object> springSessionDefaultRedisSerializer() {
//
//        return new MyJdkSerializationRedisSerializer();
//    }

//    @Bean
//    @Primary
//    public LocaleResolver localeResolver() {
//        SessionLocaleResolver sessionLocaleResolver = new SessionHeaderLocaleResolver();
//        sessionLocaleResolver.setDefaultLocale(Locale.CHINA);
//        return sessionLocaleResolver;
//    }
}
